﻿using System.Reflection;
using Abp.AutoMapper;
using Abp.Modules;
using FutureApp.Navigation;
using AutoMapper;
using System.Linq;
using FutureApp.Authorization;

namespace FutureApp
{
    /// <Module/>
    [DependsOn(typeof(FutureAppCoreModule),
        typeof(AbpAutoMapperModule))]
    public class FutureAppApplicationModule : AbpModule
    {
        /// <Initialize/>
        public override void PreInitialize()
        {
            Configuration.Authorization.Providers.Add<FutureAppAuthorizationProvider>();
            Configuration.Navigation.Providers.Add<FutureAppNavigationProvider>();
        }

        /// <Initialize/>
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
            this.AutoMapperConfigration();
        }

        //一次性加载所有映射配置
        private void AutoMapperConfigration()
        {
            Configuration.Modules.AbpAutoMapper().Configurators.Add(cfg =>
            {
                Assembly.GetExecutingAssembly().GetTypes()
                        .Where(x => x.IsSubclassOf(typeof(Profile)))
                        .ToList()
                        .ForEach(cfg.AddProfile);
            });
        }
    }
}
